<?php

/**
 * 签署公司仓库
 * @author wangwx 2015-5-22
 */
namespace common\repositories\myhtsq;
use common\repositories\BaseRepository;
use common\entities\myhtsq\ContractCompanyEntity;
class ContractCompanyRepository extends BaseRepository{

	/**
	 * 构造方法
	 * @param unknown $config (optional)
	 */
	public function __construct($config = [])
	{
		parent::__construct($config);
	}
	
	/**
	 * 根据性质id,获取公司列表
	 * @param string $propertyId 性质id
	 * @return array
	 */
	public static function getContractCompanyListByPropertyId($propertyId) {
		return ContractCompanyEntity::find()->where('find_in_set(:propertyId,property_id)')->params([':propertyId'=>$propertyId])->all();
	}
	
	/**
	 * 根据公司guid，获取公司名称
	 * @param string $companyId 公司id
	 * @return string
	 */
	public static function getContractCompanyNameByCompanyId($companyId) {
		$str = ContractCompanyEntity::find()->select('company_name')->where(['company_id'=>$companyId])->scalar();
		if (empty($str)) {
			$str = '';
		}
		return $str;
		
	}

    public static function getAllContractCompanyNameByCompanyIds($companyIds)
    {
        return ContractCompanyEntity::find()
            ->select('company_name, company_id')
            ->where(['company_id' => $companyIds])
            ->asArray()
            ->all();
    }

    /**
     * 根据签署公司名称获取ID
     *
     * @param  $name string 签署公司名称
     * @return array|null|\yii\db\ActiveRecord
     */
    public static function getCompanyIdByName($name)
    {
        $map['company_name'] = $name;

        $result = ContractCompanyEntity::find()->select('company_id')->where($map)->scalar();
        return $result;
    }
	
}